<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>企业网站管理系统--后台登录</TITLE>
<LINK rel="stylesheet" type="text/css" href="images/login.css">

<script type="text/javascript">
	function loadXMLDoc() {
		var index = 1;
		var xmlhttp;
		var username = document.getElementById("username").value;
		var password = document.getElementById("password").value;
		if (username == "") {
			document.getElementById("usernameWarn").style.display = "";
			document.getElementById("usernameWarn").innerHTML = "<font color=\"red\">*用户名不能为空</font>";
			return;
		} else {
			document.getElementById("usernameWarn").style.display = 'none';
		}
		if (password == "") {
			document.getElementById("pwdWarn").style.display = "";
			document.getElementById("pwdWarn").innerHTML = "<font color=\"red\">*密码不能为空</font>";
			return;
		} else {
			document.getElementById("pwdWarn").style.display = 'none';
		}
		if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp = new XMLHttpRequest();
		} else {// code for IE6, IE5
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.responseText == 1) { //登录成功
				if (index == 1) {
					window.location.href = "main.html";
				}
				index++;
			} else if (xmlhttp.responseText == 0) { //密码不对
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					document.getElementById("pwdWarn").style.display = "";
					document.getElementById("pwdWarn").innerHTML = "<font color=\"red\">*密码不正确</font>";
				}
			} else if (xmlhttp.responseText == -1) { //用户名不对
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					document.getElementById("usernameWarn").style.display = "";
					document.getElementById("usernameWarn").innerHTML = "<font color=\"red\">*用户名不存在</font>";
				}
			} else if (xmlhttp.responseText == -2) { //服务器出错
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					alert("服务器通信出错，请联系管理员或稍后再试！");
				}
			}
		}

		var v = document.getElementsByName("role")
		var role;
		for ( var i = 0; i < v.length; i++) {
			if (v.item(i).checked) {
				role = v.item(i).value;
			}
		}
		xmlhttp.open("GET", "login?username=" + username + "&password="
				+ password + "&role=" + role, true);
		xmlhttp.send();
	}
</script>

</HEAD>
<BODY style="BACKGROUND-COLOR: #f4f7f9">
	<DIV class="login">
		<P class="pl"></P>
		<DIV class="l"></DIV>
		<DIV class="c">

			<DIV class="to">
				<SPAN class="tol"><A class="v" href="/" target="_blank"></A></SPAN>
			</DIV>
			<DIV class="in">
				<DL>
					<DT>用户名</DT>
					<DD>
						<INPUT style="WIDTH: 150px" type="text" id="username"> <span
							style="display: none" id="usernameWarn"><font color="red">*用户名不存在</font></span>
					</DD>
					<DD class="e"></DD>
				</DL>
				<DL>
					<DT>密 码</DT>
					<DD>
						<INPUT style="WIDTH: 150px" type="password" id="password">
						<span style="display: none" id="pwdWarn"><font color="red">*密码不正确</font></span>
					</DD>
					<DD class="e"></DD>
				</DL>


				<DL>
					<DT>角色</DT>
					<DD class="e" style="width: 20px; padding-top: 4px">
						<input type="radio" name="role" value="t" />
					</DD>
					<DD class="e" style="width: 30px">教师</DD>
					<DD class="e" style="width: 20px; padding-top: 4px">
						<input type="radio" checked="checked" name="role" value="s" />
					</DD>
					<DD class="e" style="width: 40px">管理员</DD>

				</DL>


			</DIV>
			<DIV class="su">
				<SPAN><INPUT class="go" type="button" value=""
					onclick="loadXMLDoc();"></SPAN>
			</DIV>

		</DIV>
		<DIV class="r"></DIV>
		<P class="pr"></P>
	</DIV>
</BODY>
</HTML>